<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
    <el-row>
      <el-form-item label="所属APP" prop="appSource" label-width="120px">
        <el-input
          v-model="queryParams.appSource"
          placeholder="请输入所属APP"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户ID" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入用户ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="大于预估收益(分)" prop="ecpmReality" label-width="120px">
        <el-input
          v-model="queryParams.ecpmReality"
          placeholder="请输入大于预估收益(分)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建日期" prop="cjDate">
        <el-date-picker clearable
                        v-model="queryParams.cjDate"
                        type="datetimerange"
                        style="width: 350px"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        range-separator="-"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        :default-time="['00:00:00', '23:59:59']">
        </el-date-picker>
      </el-form-item>
<!--      <el-col :span="6">
      <el-form-item label="代理ID" prop="agencyId">
        <el-input
          v-model="queryParams.agencyId"
          placeholder="请输入代理ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      </el-col>-->
      <el-form-item class="left">
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-row>
    </el-form>

    <el-table v-loading="loading" :data="VideoManageList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="广告平台" align="center" prop="adPlatform" width="90px">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.ad_name" :value="scope.row.adPlatform"/>
        </template>
      </el-table-column>
      <el-table-column label="所属APP" align="center" prop="appSource" />
      <el-table-column label="用户id" align="center" prop="userId" />
      <el-table-column label="用户昵称" align="center" prop="nickName" />
      <el-table-column label="所属代理id" align="center" prop="agencyId" />
      <el-table-column label="所属代理名称" align="center" prop="agencyName" width="100px"/>
      <el-table-column label="所属推广id" align="center" prop="recommendUserId" />
      <el-table-column label="所属推广名称" align="center" prop="recommendUserName" width="100px"/>
      <el-table-column label="广告位id" align="center" prop="adId" :show-overflow-tooltip="true"/>
      <el-table-column label="ECPM" align="center" prop="ecpm">
        <template slot-scope="scope">
          <span>{{ scope.row.ecpm * 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="预估收益(分)" align="center" prop="ecpmReality" width="100px">
        <template slot-scope="scope">
          <span>{{ scope.row.ecpmReality * 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="设备型号" align="center" prop="model" />
      <el-table-column label="设备ip" align="center" prop="ip" :show-overflow-tooltip="true" width="140px"/>
      <el-table-column label="创建时间" align="center" prop="createTime" width="180px">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit-outline"
            @click="addBlackList(scope.row)"
            v-hasPermi="['blacklist:list:add']"
          >加入黑名单</el-button>
        </template>

      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="视频ID" hidden="hidden" >
          <el-input
            v-model="form.id"
            />
        </el-form-item>
        <el-form-item label="拉黑原因" prop="reason">
          <el-input
            maxlength="300"
            class="public-showWordLimit"
            type="textarea"
            v-model="form.reason"
            placeholder="请输入拉黑原因" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


  </div>
</template>

<script>
import { listVideoManage, getVideoManage,addBlackList } from "@/api/opearte/videomanage";
import {delList} from "@/api/opearte/blacklist";

export default {
  name: "VideoManage",
  dicts: ['ad_name'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 视频管理表格数据
      VideoManageList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        adPlatform: null,
        appSource: null,
        userId: null,
        agencyId: null,
        adId: null,
        ecpm: null,
        ecpmReality: null,
        model: null,
        ip: null,
        cjDate: [],
      },
      // 表单参数
      form: {},

      // 表单校验
      rules: {
        reason: [
          { required: true, trigger: 'blur', message: '请输入拉黑原因' }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    substrIP(value){
      if(value.length() > 9 ){
        return value.substr(0,9)+"...";
      }else{
        return value;
      }
    },
    /** 查询视频管理列表 */
    getList() {
      this.loading = true;
      this.addDateRange(this.queryParams, this.queryParams.cjDate,'Cj')
      listVideoManage(this.queryParams).then(response => {
        this.VideoManageList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        adPlatform: null,
        appSource: null,
        userId: null,
        agencyId: null,
        adId: null,
        ecpm: null,
        ecpmReality: null,
        model: null,
        ip: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        delFlag: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },

    /** 删除按钮操作 */
    addBlackList(row) {
      this.open = true;
      this.title = "加入黑名单"
      this.form.id=row.id;
     /* const ids = row.id || this.ids;
      this.$modal.confirm('是否确认将编号为"' + ids + '"的数据加入黑名单？').then(function() {
        return addBlackList(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("操作成功");
      }).catch(() => {});*/
    },

    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          addBlackList(this.form).then(response => {
            this.$modal.msgSuccess("新增成功");
            this.open = false;
            this.getList();
          });
        }
      });
    },
  }
};
</script>
<style>
.public-showWordLimit.el-textarea .el-input__count {
  bottom: -20px !important;
  right: 10px;
  line-height: 1.5;
}
</style>
